<template>
  <div class="app-container">
    <div class="search-container">
      <el-form :model="searchParam" :inline="true">
        <el-form-item label="工厂">
          <el-select
            v-model="searchParam.plantId"
            placeholder="请输入工厂"
            clearable
            @keyup.enter="search"
            @change="changePlant"
            filterable
          >
            <el-option
              v-for="plant in plantList"
              :key="plant.id"
              :label="plant.organizationCode"
              :value="plant.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="存货编号">
          <search-content-input
            :width="350"
            :isMultiple="true"
            :showSelectDevice="materialList"
            :plantId="searchParam.plantId"
            :maxCollapseTags="2"
            :disabled="searchParam.plantId == ''"
            @get-device="(id, object) => getDevice(id, object)"
          />
        </el-form-item>

        <el-form-item label="计划状态">
          <el-select
            v-model="searchParam.planState"
            placeholder="请选择计划状态"
            clearable
            @keyup.enter="search"
            filterable
          >
            <el-option
              v-for="item in useDictionary('plannedBatchType')"
              :key="item.value"
              :label="item.label"
              :value="Number(item.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="计划批次">
          <el-input
            v-model="searchParam.planBatch"
            placeholder="请输入计划批次"
            clearable
            @keyup.enter="search"
          />
        </el-form-item>
        <el-form-item label="计划年份">
          <el-select
            @keyup.enter="search"
            v-model="searchParam.planYear"
            placeholder="请选择计划年份"
            clearable
            @change="selectYear"
          >
            <el-option
              v-for="item in yearOptions"
              :key="item"
              :value="item"
              :label="item"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="计划月份">
          <el-select
            @keyup.enter="search"
            v-model="searchParam.planMonth"
            placeholder="请选择计划月份"
            clearable
            @change="selectMonth"
          >
            <el-option
              v-for="item in monthOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="计划周">
          <el-select
            @keyup.enter="search"
            v-model="searchParam.planWeek"
            placeholder="请选择计划周"
            clearable
            @change="selectWeek"
          >
            <el-option
              v-for="item in weekOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="switchBtn"
            ><i-ep-search />查询</el-button
          >
          <el-button @click="reset1"><i-ep-refresh />重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <template #header>
        <!-- <el-button type="success" plain @click="openDialog()"
          ><i-ep-plus />新增</el-button
        >-->
        <el-button type="primary" @click="addPlan">批量添加</el-button>
        <!-- <el-button
          type="primary"
          @click="changeSubmission()"
          :loading="changeSubLoading"
          >变更提交</el-button
        > -->
        <!-- <el-button type="danger" @click="closePlan()" :loading="closeLoading"
          >关 闭</el-button
        > -->
        <!-- <el-button type="danger" @click="deletePlan()" :loading="deleteLoading"
          >删 除</el-button
        > -->
        <!-- <el-button
          class="ml-3"
          @click="
            useDownload('/mes/mesplannedbatch/export', '计划批次', searchParam)
          "
        >
          <template #icon><i-ep-download /></template>导出</el-button
        > -->
      </template>

      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />

        <el-table-column
          label="工厂编号"
          prop="plantCode"
          min-width="150"
          show-overflow-tooltip
          align="left"
        >
        </el-table-column>
        <el-table-column
          label="状态"
          prop="planState"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.planState == 0" type="success">{{
              useDictionary("plannedBatchType", scope.row.planState ?? "")
            }}</el-tag>
            <el-tag v-show="scope.row.planState != 0">{{
              useDictionary("plannedBatchType", scope.row.planState ?? "")
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="卷料状态" width="100" align="center">
          <template #default="{ row, $index }">
            <!-- <svg-icon
                icon-class="material"
                class="text-[17px] !mr-[0px] cursor-pointer color-[#409eff]"
                @click="selectMaterials(row, $index)"
              /> -->
            <!-- <el-tag v-if="row.requestPlanList.length === 0" type="success"
                ><svg-icon
                  icon-class="yifenpei"
                  class="text-[14px] c-##67c23a"
                />已分配</el-tag
              > -->
            <el-tooltip
              v-if="row.listRequestPlan && row.listRequestPlan?.length !== 0"
              content="已分配"
              placement="bottom"
              effect="light"
            >
              <svg-icon
                icon-class="yifenpei"
                class="text-[20px] c-#67C23A !mr-0"
              />
            </el-tooltip>

            <el-tooltip
              v-else
              content="待分配"
              placement="bottom"
              effect="light"
            >
              <svg-icon
                icon-class="daifenpei"
                class="text-[20px] c-#E6A23C !mr-0"
              />
            </el-tooltip>

            <!-- <el-tag v-if="row.requestPlanList.length !== 0" type="warning"
                >待分配</el-tag
              > -->
          </template>
        </el-table-column>
        <el-table-column
          label="计划年份"
          prop="planYear"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope"> {{ scope.row.planYear }}年 </template>
        </el-table-column>
        <el-table-column
          label="计划月份"
          prop="planMonth"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope"> {{ scope.row.planMonth }}月 </template>
        </el-table-column>
        <el-table-column
          label="卷料"
          prop="componentMaterialName"
          show-overflow-tooltip
          min-width="180"
          header-align="center"
          align="right"
        >
          <template #default="{ $index, row }">
            <span
              >{{ row.componentMaterialCode
              }}{{
                row.componentMaterialName && row.componentMaterialCode
                  ? "-"
                  : ""
              }}{{ row.componentMaterialName }}</span
            >
          </template>
        </el-table-column>
        <el-table-column
          label="重量"
          prop="materialWeight"
          show-overflow-tooltip
          min-width="100"
          header-align="center"
          align="right"
        >
          <template #default="{ $index, row }">
            <span>{{ row.materialWeight }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="理论数量"
          prop="theoryQuantity"
          show-overflow-tooltip
          min-width="100"
          header-align="center"
          align="right"
        >
          <template #default="{ $index, row }">
            <span>{{ row.theoryQuantity }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="存货编码"
          prop="materialCode"
          min-width="180"
          show-overflow-tooltip
          align="left"
        >
          <template #default="scope">
            {{ scope.row.materialCode }}-{{ scope.row.materialName }}
          </template>
        </el-table-column>
        <el-table-column
          label="图号"
          prop="figureNumber"
          min-width="180"
          show-overflow-tooltip
          align="left"
        >
        </el-table-column>
        <el-table-column
          label="计划批次"
          prop="planBatch"
          min-width="100"
          show-overflow-tooltip
          align="right"
        >
        </el-table-column>
        <el-table-column
          label="批次数量"
          prop="planBatchNum"
          min-width="100"
          show-overflow-tooltip
          align="right"
        >
        </el-table-column>
        <el-table-column
          label="完成报工数量"
          prop="planFinishQuantity"
          min-width="150"
          show-overflow-tooltip
          align="right"
        >
        </el-table-column>
        <el-table-column
          label="待判定数量"
          prop="invalidQuantity"
          min-width="150"
          show-overflow-tooltip
          align="right"
        >
        </el-table-column>
        <el-table-column
          label="计划剩余数量"
          prop="planFinishQuantity"
          min-width="150"
          show-overflow-tooltip
          align="right"
        >
          <template #default="scope">
            {{
              scope.row.planBatchNum -
              scope.row.planFinishQuantity +
              scope.row.invalidQuantity
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="卷料操作"
          align="center"
          fixed="right"
          width="130"
        >
          <template #default="{ row, $index }">
            <el-button
              type="primary"
              @click="selectMaterials(row, $index)"
              class="h-[28px]"
              >选择</el-button
            >
            <!-- <el-button
                v-if="row.planState == 0 && !row.isSureRequestPlan"
                class="text-[12px]"
                @click="cancelRequstPlan($index)"
                >取消确认</el-button
              > -->
          </template>
        </el-table-column>
      </el-table>

      <!-- <el-pagination
        :background="true"
        :current-page="pageable.pageNum"
        :page-size="pageable.pageSize"
        :page-sizes="[10, 25, 50, 100]"
        :total="pageable.total"
        layout="total, sizes, prev, pager, next, jumper"
        class="mt-[20px]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      /> -->
    </el-card>

    <mesplannedbatch-edit
      :visible="addDialog.visible"
      :title="addDialog.title"
      :data="addDialog.data"
      @reset-table="(id:string) => (id?.length ? getTableList() : reset())"
      :is-readonly="addDialog.readvisible"
      @change-visible="changeVisible"
    />

    <SelectMaterialPlanDialog
      v-model:visible="materialsSelect.visible"
      :data="materialsSelect.data"
      :allocationId="materialsSelect.allocationId"
      :eldIds="materialsSelect.eldIds"
      :readonly="materialsSelect.readonly"
      :materialId="materialsSelect.materialId"
      :materialCode="materialsSelect.materialCode"
      :planQuantity="materialsSelect.planQuantity"
      :isMultiple="true"
      :plantId="searchParam?.plantId"
      :companyId="searchedCompanyId"
      :rowIndex="materialsSelect?.rowIndex"
      @echo-info="getMaterialsSelect"
    />
  </div>
</template>

<script setup lang="ts">
import { useTable, useDownload, useDictionary } from "@/utils/useTable";
import dayjs from "dayjs";
import request from "@/utils/request";
import {
  getFirstWorkShopList,
  getMesRouteGroupList,
  getWorkCenterDetail,
  getCurrentYield,
  getFreeDetails,
  getMonthList,
  getYearList,
  getMaterialList,
  getDateshiftCount,
  getOtherWorkShopList,
} from "@/utils/commonData";

import {
  getWeeksInYear,
  getWeekNumber,
  week_date,
  getDaysOfCurrentWeek,
} from "@/utils/dateUtils";

defineOptions({
  name: "MESMESPLANNEDBATCH",
  inheritAttrs: false,
});

// 请求参数
const requestApi = "/mes/mesplannedbatch/queryByPage";

// 是否需要分页
const pagination = true;

const initParam = {};
const currentYear = new Date().getFullYear(); // 当前年份
const currentMonth = dayjs().month() + 1; // 当前年份
const currentWeek = getWeekNumber(new Date()); // 当前第几周
// 初始化搜索参数数据
const searchParamInit = {
  plantId: "",
  planState: "",
  plantCode: "",
  materialId: "",
  materialCode: "",
  planBatch: "",
  planYear: currentYear,
  planMonth: currentMonth,
  figureNumber: "",
  materialIds: [],
};

const deleteParam = {
  api: "/mes/mesplannedbatch/delete",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

const dataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// 表格操作 Hooks

// 获取年度列表
const yearOptions = ref();
// 获取周列表
// const monthOptions = ref<OptionType[]>();
const weekOptions = ref<OptionType[]>();

// 月份份
const monthOptions = [
  {
    id: 1,
    name: "1月",
  },
  {
    id: 2,
    name: "2月",
  },
  {
    id: 3,
    name: "3月",
  },
  {
    id: 4,
    name: "4月",
  },
  {
    id: 5,
    name: "5月",
  },
  {
    id: 6,
    name: "6月",
  },
  {
    id: 7,
    name: "7月",
  },
  {
    id: 8,
    name: "8月",
  },
  {
    id: 9,
    name: "9月",
  },
  {
    id: 10,
    name: "10月",
  },
  {
    id: 11,
    name: "11月",
  },
  {
    id: 12,
    name: "12月",
  },
];

const materialList = ref([]);
// 获取选中的数据进行回显并赋值
function getDevice(Ids: string[], Objects: any) {
  if (Ids.length > 0) {
    searchParam.value.materialIds = Ids;
  } else {
    searchParam.value.materialIds = [];
  }
}
function changeVisible(value: boolean) {
  addDialog.visible = value;
  if (!value) {
    addDialog.data = {};
  }
}

const reset1 = () => {
  reset();
  materialList.value = [];
};

onMounted(async () => {
  getPlantList();
  // 获取年列表
  yearOptions.value = await getYearList();
  // 获取周搜索列表
  weekOptions.value = getMonthList(currentYear);
});

// 改变年份
const selectYear = (e) => {
  if (e) {
    searchParam.value = { ...searchParam.value, planWeek: "" };
    weekOptions.value = getMonthList(e);
  } else {
    weekOptions.value = [];
    searchParam.value = { ...searchParam.value, planWeek: "" };
  }
};
// 改变月份份
const selectMonth = (e) => {
  if (e) {
    searchParam.value.planMonth = e;
  } else {
    searchParam.value.planMonth = "";
  }
};
// 改变周
const selectWeek = (e) => {
  if (e) {
    searchParam.value.planWeek = e;
  } else {
    searchParam.value.planWeek = "";
  }
};

// 获取工厂列表
const plantId = ref("");
const plantList: any = ref([]);
const getPlantList = async () => {
  const res1 = await request({
    url: "system/sysOrganization/getList",
    method: "post",
    data: { organizationType: 3 },
  });
  plantList.value = res1.data;
  searchParam.value.plantId = plantList.value[0].id;
  plantId.value = plantList.value[0].id;
  changePlant(plantList.value[0].id);
};
const companyId = ref("");
const searchedCompanyId = ref("");
const changePlant = (e) => {
  companyId.value =
    plantList.value.find((item) => item.id === e)?.parentId ?? "";
  searchedCompanyId.value = toRaw(companyId.value);
};
const addDialog = reactive<DialogOption>({
  visible: false,
  readvisible: false,
  title: "",
  data: {},
});

// 点击切换按钮
const tableData = ref([]);
const ids = ref<string[]>([]);
const loading = ref(false);
const searchParam = ref({ ...searchParamInit });

const isSearched = ref(false);

/** 行复选框选中  */
function handleSelectionChange(selection: any) {
  ids.value = selection.map((item: any) => item.id || item.key);
}
const switchBtn = () => {
  isSearched.value = true;
  if (!searchParam.value.plantId) {
    ElMessage.error("请选择工厂");
    return;
  } else if (!searchParam.value.planYear) {
    ElMessage.error("请选择工作年");
    return;
  } else if (!searchParam.value.planMonth) {
    ElMessage.error("请选择工作月");
    return;
  } else {
    search();
  }
};
// 搜索
const search = async () => {
  loading.value = true;
  tableData.value = [];
  const { data } = await request({
    url: "/mes/mesplannedbatch/getRollList",
    method: "post",
    data: toRaw(searchParam.value),
  }).catch(() => {
    loading.value = false;
  });
  tableData.value = data;
  isSearched.value = true;
  loading.value = false;
};

const reset = () => {
  searchParam.value = { ...searchParamInit };

  searchParam.value.plantId = plantId.value;

  if (plantId.value) {
    changePlant(plantId.value);
  }
  tableData.value = [];
  materialList.value = [];
  isSearched.value = false;
};

// 定义钢卷选择选择器弹窗参数
const materialsSelect = reactive<DialogOption>({
  allocationId: "",
  rowIndex: "",
  visible: false,
  eldIds: [],
  data: [],
  materialId: "",
  materialCode: "",
  planQuantity: "",
});
interface SelectOption {
  id?: string;
}
const materialsOptions: any = ref([]); // 选择器 list
// 添加卷料
const MaterialsList = ref([]);
const MaterialsList1 = ref([]);
const addPlan = async () => {
  if (!isSearched.value) {
    ElMessage.error("请搜索后，再添加");
    return;
  } else {
    if (ids.value.length > 0) {
      MaterialsList.value = [];
      MaterialsList1.value = [];
      tableData.value.forEach((item, index) => {
        ids.value.forEach((item1) => {
          if (item.id == item1) {
            MaterialsList1.value.push(item.routingAllocationId);
          }
        });
      });
      tableData.value.forEach((item, index) => {
        ids.value.forEach((item1) => {
          if (item.id == item1) {
            MaterialsList.value.push({ row: item, rowIndex: index });
          }
        });
      });
      // let a = await isMainMaterial(MaterialsList1.value);

      let hh = MaterialsList.value.every(
        (item) =>
          item.row.componentMaterialId ===
          MaterialsList.value[0].row.componentMaterialId
      );

      if (hh) {
        const { row, rowIndex } = MaterialsList.value[0];
        selectIdsMaterials(row, rowIndex);
      } else {
        ElMessage.error("请选择相同物料或者未设置卷料！");
        return;
      }
      // console.log(" MaterialsList.value[0]", MaterialsList.value[0]);

      // const { row, rowIndex } = MaterialsList.value[0];
      // selectIdsMaterials(row, rowIndex);
      // MaterialsList.value.forEach((item, index) => {
      //   if(item.item.materialId)
      // })
    } else {
      ElMessage.error("请选择至少一条数据");
      return;
    }
  }
};

// 验证物料号是否相同
function isMainMaterial(result) {
  return new Promise(async (resolve, reject) => {
    const { data } = await request({
      url: "/mes/mesroutingbom/isMainMaterial",
      method: "post",
      data: result,
    });
    resolve(data);
  });
}

// 钢卷选择
async function selectMaterials(row, rowIndex) {
  // const { data } = await request({
  //   url: `/mes/mesroutingbom/listMainMaterial/${row.routingAllocationId}`,
  //   method: "GET",
  //   data: {},
  // });
  // console.log("data", data);
  // console.log("routingAllocationId", row.routingAllocationId);
  // if (!data || !data.length || data.length === 0) {
  //   ElMessage.error("请给当前工序设置卷料");
  // } else {
  materialsSelect.eldIds = [];
  if (row.id) {
    const current = tableData.value.filter((item: any) => item.id === row.id);
    if (current && current.length) {
      let list: string[] = [];
      current[0].listRequestPlan.map((self: any) => {
        list.push(self.materialBarcode);
      });
      materialsSelect.eldIds = list || [];
    }
  }

  materialsSelect.data = row.listRequestPlan || [];
  materialsSelect.allocationId = row.routingAllocationId;
  materialsSelect.materialId = row.componentMaterialId;
  materialsSelect.materialCode = row.componentMaterialCode;
  materialsSelect.planQuantity = row.planBatchNum;
  materialsSelect.rowIndex = rowIndex;
  materialsSelect.readonly = false;
  materialsSelect.visible = true;
  // }
}

async function selectIdsMaterials(row, rowIndex) {
  // const { data } = await request({
  //   url: `/mes/mesroutingbom/listMainMaterial/${row.routingAllocationId}`,
  //   method: "GET",
  //   data: {},
  // });
  // !data || !data.length || data.length === 0
  if (false) {
    ElMessage.error("请给当前工序设置卷料");
  } else {
    materialsSelect.eldIds = [];
    if (row.id) {
      const current = tableData.value.filter((item: any) => item.id === row.id);
      if (current && current.length) {
        let list: string[] = [];
        current[0].listRequestPlan.map((self: any) => {
          list.push(self.materialBarcode);
        });
        // materialsSelect.eldIds = list || [];
        // 多选时清空id
        if (ids.value.length == 1) {
          materialsSelect.eldIds = list || [];
        } else {
          materialsSelect.eldIds = [];
        }
      }
    }

    // 多选时清空勾选的对号
    if (ids.value.length == 1) {
      materialsSelect.data = row.listRequestPlan || [];
    } else {
      materialsSelect.data = [];
    }

    // materialsSelect.data = row.listRequestPlan || [];
    // materialsSelect.planQuantity = 0;

    // tableData.valu.forEach((item, index) => {
    //   ids.value.forEach((item1) => {
    //     if (item.id == item1) {
    //       materialsSelect.planQuantity += item.planQuantity;
    //     }
    //   });
    // });
    materialsSelect.allocationId = row.routingAllocationId;
    materialsSelect.materialId = row.componentMaterialId;
    materialsSelect.materialCode = row.componentMaterialCode;
    materialsSelect.planQuantity = row.planBatchNum;
    materialsSelect.rowIndex = rowIndex;
    materialsSelect.readonly = false;
    materialsSelect.visible = true;
  }
}
// 接收钢卷选择器回调参数
function getMaterialsSelect(options: any, index, Allkg, AllNum) {
  // 新建的计划，可以修改
  // 没勾选时触发

  if (ids.value.length == 0) {
    materialsOptions.value = options;

    tableData.value[index].listRequestPlan = options;

    if (options.length) {
      let sumQuantity = 0;
      options.map((item) => {
        sumQuantity += item.theoryQuantity ?? 0;
      });
      // tableData.value[index].defaultPlanQuantity = AllNum;
      tableData.value[index].listRequestPlan = options;
      // 理论 重量
      tableData.value[index].theoryQuantity = AllNum;
      tableData.value[index].materialWeight = Allkg;
    } else {
      // tableData.value[index].defaultPlanQuantity = "";

      tableData.value[index].listRequestPlan = [];
    }
    sureRequstPlan(index);
  } else if (ids.value.length == 1) {
    // 勾选一个时
    tableData.value[index].listRequestPlan = options;

    if (options.length) {
      let sumQuantity = 0;
      options.map((item) => {
        sumQuantity += item.theoryQuantity ?? 0;
      });
      // tableData.value[index].defaultPlanQuantity = AllNum;
      tableData.value[index].listRequestPlan = options;
      // 理论 重量
      tableData.value[index].theoryQuantity = AllNum;
      tableData.value[index].materialWeight = Allkg;
    } else {
      // tableData.value[index].defaultPlanQuantity = "";
      tableData.value[index].listRequestPlan = [];
    }

    submits();
  } else {
    // 勾选多个时
    let mm = Allkg;
    let bb = AllNum;
    let sumQuantity = 0;
    options.map((item) => {
      sumQuantity += item.theoryQuantity ?? 0;
    });
    // 先把 理论 重量 卷料数量为0
    tableData.value.forEach((item, index) => {
      MaterialsList.value.forEach((item2, index2) => {
        if (item2.row.id == item.id && index == item2.rowIndex) {
          item.listRequestPlan = options;
          if (options.length) {
            item.defaultPlanQuantity = 0;
            item.listRequestPlan = options;
            item.theoryQuantity = 0;
            item.materialWeight = 0;
          } else {
            item.defaultPlanQuantity = "";
            item.listRequestPlan = [];
            // 理论 重量
            item.theoryQuantity = "";
            item.materialWeight = "";
          }
        }
      });
    });

    let allNumber = MaterialsList.value.length;
    tableData.value.forEach((item, index) => {
      MaterialsList.value.forEach((item2, index2) => {
        if (item2.row.id == item.id && index == item2.rowIndex) {
          if (MaterialsList.value.length - 1 == index2) {
            tableData.value[index].materialWeight =
              Math.floor(mm / allNumber) + (mm % allNumber);
          } else {
            tableData.value[index].materialWeight = Math.floor(mm / allNumber);
          }
        }
      });
    });

    tableData.value.forEach((item, index) => {
      MaterialsList.value.forEach((item2, index2) => {
        if (item2.row.id == item.id && index == item2.rowIndex) {
          if (MaterialsList.value.length - 1 == index2) {
            tableData.value[index].theoryQuantity =
              Math.floor(bb / allNumber) + (bb % allNumber);
          } else {
            tableData.value[index].theoryQuantity = Math.floor(bb / allNumber);
          }
        }
      });
    });
    submits();
  }

  // tableData.value.forEach((item2, index2) => {
  //   if (item2.listRequestPlan.length > 0) {
  //     item2.requestPlanList = item2.listRequestPlan;
  //   }
  // });
  // console.log("卷料确认", tableData.value);

  // const postUrl = resolveUrl("保存");
  // // 最后提交
  // lastMaterialsSubmit(tableData.value, "保存", postUrl);
}
// 批量确认
const submits = async () => {
  if (!isSearched.value) {
    ElMessage.error("请切换到对应排产后，再添加");
    return;
  } else {
    await request({
      url: `/mes/mesplannedbatch/saveRoll`,
      method: "post",
      data: tableData.value,
    }).then((res) => {
      if (res.code === 200) {
        ElMessage.success("确认成功");
        search(); // 更新数据
      }
    });
  }
};

// 确认卷料
async function sureRequstPlan(index: number) {
  await request({
    url: `/mes/mesplannedbatch/saveRoll`,
    method: "post",
    data: tableData.value,
  }).then((res) => {
    if (res.code === 200) {
      ElMessage.success("确认成功");
      search(); // 更新数据
    }
  });
}
</script>
